package com.qyer.commons.place;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.qyer.commons.enums.PlaceType;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

import java.io.Serializable;

/**
 * User: Z J Wu Date: 2016/03/06 Time: 01:28 Package: com.qyer.commons.place
 */
@JsonInclude(JsonInclude.Include.NON_NULL)
public class QyerPlace implements Serializable {

  public static final QyerPlace EARTH = new QyerPlace(1, 0, "地球", "Earth", "DiQiu",
                                                      PlaceType.OTHER);

  @JsonProperty
  protected int id;

  @JsonIgnore
  protected int parentId;

  @JsonProperty
  protected String name;

  @JsonProperty("name_en")
  protected String nameEn;

  @JsonProperty("name_py")
  protected String namePY;

  @JsonProperty("type")
  protected PlaceType placeType;

  public QyerPlace() {
  }

  public QyerPlace(int id, int parentId, String name, PlaceType placeType) {
    this.id = id;
    this.parentId = parentId;
    this.name = name;
    this.placeType = placeType;
  }

  public QyerPlace(int id, int parentId, String name, String nameEn, String namePY,
                   PlaceType placeType) {
    this.id = id;
    this.parentId = parentId;
    this.name = name;
    this.nameEn = nameEn;
    this.namePY = namePY;
    this.placeType = placeType;
  }

  public static Province createChinaProvince(int id, int parentId, String name) {
    return new Province(id, parentId, name);
  }

  public static Continent createContinent(int id, int parentId, String name) {
    return new Continent(id, parentId, name);
  }

  public static Continent createContinentWithEnglishPY(int id, int parentId, String name,
                                                       String nameEn, String namePY) {
    return new Continent(id, parentId, name, nameEn, namePY);
  }

  public static Country createCountry(int id, int parentId, String name) {
    return new Country(id, parentId, name);
  }

  public static Country createCountryWithEnglishPY(int id, int parentId, String name, String nameEn,
                                                   String namePY) {
    return new Country(id, parentId, name, nameEn, namePY);
  }

  public static City createCity(int id, int parentId, String name) {
    return new City(id, parentId, name, null, null);
  }

  public static City createCityWithEnglishPY(int id, int parentId, String name, String nameEn,
                                             String namePY) {
    return new City(id, parentId, name, nameEn, namePY);
  }

  public int getId() {
    return id;
  }

  public void setId(int id) {
    this.id = id;
  }

  public int getParentId() {
    return parentId;
  }

  public void setParentId(int parentId) {
    this.parentId = parentId;
  }

  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = name;
  }

  public String getNameEn() {
    return nameEn;
  }

  public void setNameEn(String nameEn) {
    this.nameEn = nameEn;
  }

  public String getNamePY() {
    return namePY;
  }

  public void setNamePY(String namePY) {
    this.namePY = namePY;
  }

  public PlaceType getPlaceType() {
    return placeType;
  }

  public void setPlaceType(PlaceType placeType) {
    this.placeType = placeType;
  }

  @Override
  public String toString() {
    return new ToStringBuilder(this, ToStringStyle.SIMPLE_STYLE).append("placeType", placeType)
                                                                .append("id", id)
                                                                .append("parentId", parentId)
                                                                .append("name", name)
                                                                .append("nameEn", nameEn)
                                                                .append("namePY", namePY)
                                                                .toString();
  }

}
